package com.mall.logic.service.authority.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.mall.logic.dal.authority.SysMenuDao;
import com.mall.logic.dal.authority.bean.SysMenu;
import com.mall.logic.rpc.member.bean.MenuVo;
import com.mall.logic.service.authority.SysMenuService;

@Service("sysMenuService")
public class SysMenuServiceImpl implements SysMenuService {

	@Autowired
	private SysMenuDao sysMenuDao;
	
	public List<MenuVo> getMenuList() {
		List<MenuVo> menuVos = new ArrayList<MenuVo>();
		//获取一级菜单
		List<SysMenu> menus = sysMenuDao.getUserMenu(1);
		for (SysMenu sysMenu : menus) {
			MenuVo menuVo = new MenuVo();
			menuVo.setDataId(sysMenu.getHtmlurl());
			menuVo.setHref(sysMenu.getUrl());
			menuVo.setText(sysMenu.getName());
			menuVo.setType(sysMenu.getType().toString());
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("type", 2);
			map.put("menuKy", sysMenu.getMenuKy());
			//获取二级菜单
			List<SysMenu> menus2 = sysMenuDao.getUserMenu2(map);
			List<MenuVo> menuVos2 = new ArrayList<MenuVo>();
			for (SysMenu sysMenu2 : menus2) {
				MenuVo menuVo1 = new MenuVo();
				menuVo1.setDataId(sysMenu2.getHtmlurl());
				menuVo1.setHref(sysMenu2.getUrl());
				menuVo1.setText(sysMenu2.getName());
				menuVo1.setType(sysMenu2.getType().toString());
				menuVos2.add(menuVo1);
			}
			menuVo.setMenuVos(menuVos2);
			menuVos.add(menuVo);
		}
		return menuVos;
	}

	
}
